/// <reference path="deck.core.js" />
/// <reference path="jquery-1.6.2-vsdoc.js" />
/// <reference path="modernizr-2.0.6-development-only.js" />
/// <reference path="shcore.js" />
/// <reference path="shbrushjscript.js" />
/// <reference path="shbrushxml.js" />

(function ($) {
	window.html5today = {

		init: function () {
			/// <summary>
			/// Initializes the app on startup. This method is intended to be run immediately and will call 
			/// <see cref="html5today.load"/> when the <see cref="document.onready"/> event is triggered.
			/// </summary>

			// init feature detection
			html5today.features.init();

			// standard features
			// TODO: yepnope({ test: (html5today.features.sitePinned), yep: 'scripts/features/pin-site.js' });
			// TODO: yepnope({ test: (html5today.features.performanceNavigation), yep: 'scripts/features/perfint-nav.js' });

			$(html5today.load);
		},


		load: function () {
			/// <summary>
			/// Loads the app after everything has been initialized. This method is intended to be called when the 
			/// <see cref="document.onready"/> event is triggered.
			/// </summary>

			// init slide deck
			$.deck('.slide');

			// init syntax highlighter
			SyntaxHighlighter.all();
		},


		features: {
			init: function (hc) {
				/// <summary>
				/// Performs feature detection checks not currently supported by Modernizr.
				/// </summary>
				/// <param name="hc">Placeholder for a collection of CSS classes to add to the html element.</param>

				hc = [];

				// browsers; see: #semantics-forms-inputtypes
				hc.push(($.browser.msie   ? '' : 'no-') + 'msie');
				hc.push(($.browser.webkit ? '' : 'no-') + 'webkit');

				// input types; see: #detect-js, #semantics-forms-inputtypes
				hc.push((Modernizr.inputtypes.color    ? '' : 'no-') + 'inputcolor');
				hc.push((Modernizr.inputtypes.datetime ? '' : 'no-') + 'inputdatetime');
				hc.push((Modernizr.inputtypes.email    ? '' : 'no-') + 'inputemail');
				hc.push((Modernizr.inputtypes.number   ? '' : 'no-') + 'inputnumber');
				hc.push((Modernizr.inputtypes.range    ? '' : 'no-') + 'inputrange');
				hc.push((Modernizr.inputtypes.search   ? '' : 'no-') + 'inputsearch');
				hc.push((Modernizr.inputtypes.tel      ? '' : 'no-') + 'inputtel');
				hc.push((Modernizr.inputtypes.url      ? '' : 'no-') + 'inputurl');

				// form fields; see: #semantics-forms
				hc.push(('options'     in document.createElement('datalist') ? '' : 'no-') + 'datalist');
				hc.push(('keytype'     in document.createElement('keygen')   ? '' : 'no-') + 'keygen');
				hc.push(('max'         in document.createElement('meter')    ? '' : 'no-') + 'meter');
				hc.push(('onforminput' in document.createElement('output')   ? '' : 'no-') + 'output');
				hc.push(('max'         in document.createElement('progress') ? '' : 'no-') + 'progress');

				// interactive elements; see: #semantics-interactive
				hc.push(('open'  in document.createElement('details') ? '' : 'no-') + 'details');
				hc.push(('label' in document.createElement('menu')    ? '' : 'no-') + 'menu');

				// offline/storage; see: #offstore
				hc.push((typeof FileReader != 'undefined' ? '' : 'no-') + 'filereader');

				// device access; see: #device
				hc.push(('capture' in document.createElement('input') ? '' : 'no-') + 'mediacapture');

				// connectivity; see: #connect
				hc.push((typeof EventSource !== 'undefined' ? '' : 'no-') + 'eventsource');
				
				// audio/video formats; see: #detect-js, #media
				switch (Modernizr.audio.mp3) {
					case 'probably': hc.push('mp3-probably'); break;
					case 'maybe': hc.push('mp3-maybe'); break;
					default: hc.push('no-mp3'); break;
				}
				switch (Modernizr.video.h264) {
					case 'probably': hc.push('h264-probably'); break;
					case 'maybe': hc.push('h264-maybe'); break;
					default: hc.push('no-h264'); break;
				}

				/*
				// window.performance.timing
				html5today.features.performance = window.performance;
				html5today.features.performanceNavigation = window.performance && window.performance.navigation;
				html5today.features.performanceTiming = window.performance && window.performance.timing;

				// sitePinning/sitePinned
				try {
					html5today.features.sitePinned = window.external.msIsSiteMode();
					html5today.features.sitePinning = true;
				} catch (e) {
					/**
					* Source: window.external.msIsSiteMode()
					* Reason: browser doesn't support pinning
					* Action: set flag
					* /
					html5today.features.sitePinning = false;
				}
				*/

				// update <html class>
				$('html:first').addClass(hc.join(' '));
			}
		}

	};
})(jQuery);


// initialize now
html5today.init();

// load after page is ready
$(html5today.load);